package com.mmp.main.servlet;

import java.io.IOException;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mmp.common.bo.Message;
import com.mmp.common.bo.Message.MESSAGE_TYPE;
import com.mmp.common.servlet.BasicServlet;
import com.mmp.main.entity.SpInventoryContent;
import com.mmp.main.util.Default;
import com.mmp.main.util.WebUtil;

@WebServlet(urlPatterns = { "/UpdateSPCategory" })
public class SearchForSPCategoryProcessServlet extends BasicServlet {

	private static HashMap<String, String> destinations;

	static {
		destinations = new HashMap<String, String>();
		destinations.put("UpdateSPCategory", "UpdateSPCategoryDisplay");
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		SpInventoryContent spInventoryContent = dbQueryManager.getSpInventoryContentWithStats(
				getSessionSiteId(request), WebUtil.getParamValue(request, "code", null));// getSPCategory(request);

		if (spInventoryContent == null) {
			setMessage(request, new Message("لم يتم العثور علي أي نتائج موافقة لبحثك", MESSAGE_TYPE.ERROR));
			basicForward(request, response, WebUtil.getSearchDisplayURL(request));
			return;
		}

		request.setAttribute(Default.SP_CATEGORY_INFO_ATTR_NAME, spInventoryContent);
		basicForward(request, response, getSearchDestination(destinations, request));
	}

	/*
	 * private SpInventoryContent getSPCategory(HttpServletRequest request) {
	 * SpInventoryContent spInventoryContent = new SpInventoryContent();
	 * spInventoryContent.setCode(WebUtil.getParamValue(request, "code", ""));
	 * List<SpInventoryContent> list = dbm.find(spInventoryContent); if (list !=
	 * null && list.size() == 1) return list.get(0); return null; }
	 */
}
